package com.nb.controller.patient;


import com.nb.dto.patient.AppointmentDTO;
import com.nb.dto.patient.PatientInfoDTO;
import com.nb.dto.patient.ScheduleDetailDTO;
import com.nb.dto.patient.ScheduleOverviewDTO;
import com.nb.result.Result;
import com.nb.service.PatientService;
import com.nb.vo.patient.*;
import io.swagger.annotations.Api;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 患者相关接口
 */
@Slf4j
@Api(tags = "患者相关接口")
@RestController
@RequestMapping("/api/patient")
public class PatientController {

    @Autowired
    private PatientService patientService;


    /**
     * 获取患者信息
     *
     * @param request HTTP请求
     * @return 患者信息
     */
    @GetMapping("/info")
    public Result<PatientInfoVO> getPatientInfo(HttpServletRequest request) {

        PatientInfoVO patientInfoVO = patientService.getPatientInfo();

        return Result.success(patientInfoVO);

    }

    /**
     * 修改患者信息
     *
     * @param patientInfoDTO 患者信息
     * @return 修改结果
     */
    @PatchMapping("/modifyInfo")
    public Result<String> modifyPatientInfo(@RequestBody PatientInfoDTO patientInfoDTO) {
        patientService.updatePatientInfo(patientInfoDTO);
        return Result.success("修改成功");
    }


    /**
     * 获取号源查询列表
     *
     * @return 号源查询列表
     */
    @GetMapping("/getNumberSourceList")
    public Result<List<SourceQueryVO>> getNumberSourceList() {
        List<SourceQueryVO> sourceList = patientService.getNumberSourceList();
        return Result.success(sourceList);
    }

    /**
     * 获取所有订单
     *
     * @return 订单列表
     */
    @GetMapping("/getAllOrders")
    public Result<List<OrderVO>> getAllOrders() {
        List<OrderVO> ordersList = patientService.getAllOrders();
        return Result.success(ordersList);
    }

    /**
     * 缴费
     *
     * @param id 订单ID
     * @return 支付结果
     */
    @PatchMapping("/pay")
    public Result<String> pay(String id) {
        patientService.pay(id);
        return Result.success("支付成功");

    }


    /**
     * 获取最近一次挂号情况
     *
     * @return 挂号情况
     */
    @GetMapping("/getLatestRegistration")
    public Result<LatestRegistrationVO> getLatestRegistration() {
        LatestRegistrationVO latestRegistrationVO = patientService.getLatestRegistration();
        return Result.success(latestRegistrationVO);

    }

    /**
     * 获取科室列表
     *
     * @return 科室列表
     */
    @GetMapping("/getDepartmentList")
    public Result<List<DepartmentVO>> getDepartmentList() {
        List<DepartmentVO> departmentList = patientService.getDepartmentList();
        return Result.success(departmentList);
    }

    /**
     * 获取科室详情
     *
     * @param id 科室ID
     * @return 科室详情
     */
    @GetMapping("/getDepartmentDetail")
    public Result<DepartmentDetailVO> getDepartmentDetail(String id) {
        DepartmentDetailVO departmentDetailVO = patientService.getDepartmentDetail(id);
        return Result.success(departmentDetailVO);

    }

    /**
     * 获取科室医生
     *
     * @param id 科室ID
     * @return 医生列表
     */
    @GetMapping("/getDepartmentDoctor")
    public Result<List<DepartmentDoctorVO>> getDepartmentDoctor(String id) {
        List<DepartmentDoctorVO> departmentDoctorList = patientService.getDepartmentDoctor(id);
        return Result.success(departmentDoctorList);
    }

    /**
     * 获取排班概览
     *
     * @param scheduleOverviewDTO 排班概览请求参数
     * @return 排班概览列表
     */
    @PostMapping("/getScheduleOverview")
    public Result<List<ScheduleOverviewVO>> getScheduleOverview( @RequestBody ScheduleOverviewDTO scheduleOverviewDTO) {
        List<ScheduleOverviewVO> scheduleOverviewList = patientService.getScheduleOverview(scheduleOverviewDTO);
        return Result.success(scheduleOverviewList);

    }

    /**
     * 获取排班详情
     *
     * @param scheduleDetailDTO 排班详情请求参数
     * @return 排班详情
     */
    @PostMapping("/getScheduleDetail")
    public Result<ScheduleDetailVO> getScheduleDetail(@RequestBody ScheduleDetailDTO scheduleDetailDTO) {
        ScheduleDetailVO scheduleDetail = patientService.getScheduleDetail(scheduleDetailDTO);
        return Result.success(scheduleDetail);
    }

    /**
     * 预约挂号
     *
     * @param appointmentDTO 预约信息
     * @return 预约结果
     */
    @PostMapping("/makeAppointment")
    public Result<String> makeAppointment(@RequestBody AppointmentDTO appointmentDTO) {
        patientService.makeAppointment(appointmentDTO);
        return Result.success("预约成功");
    }




}
